Skip to content

fix(artifacts-init): honor gh/glab git_protocol when picking push URL - #1469

Closed
0xDevNinja wants to merge 2 commits into
garrytan:mainfrom
0xDevNinja:fix/1348-honor-git-protocol
Closed

0xDevNinja wants to merge 2 commits into
garrytan:mainfrom
0xDevNinja:fix/1348-honor-git-protocol

Conversation

@0xDevNinja

@0xDevNinja 0xDevNinja commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • gstack-artifacts-init now honors gh config get git_protocol (and glab config get git_protocol for the gitlab branch) when deriving the push URL.
  • New --push-protocol auto|https|ssh flag lets users pin explicitly. auto is the default.
  • Empty / unreadable config falls back to SSH, so users who never set git_protocol see no change.
  • 7 new tests cover all four auto paths (github/gitlab × https/ssh), both explicit overrides, the unset-fallback, and invalid-value rejection.

Fixes #1348.

Why

bin/gstack-artifacts-init:184 (post v1.27.0.0 rename from gstack-brain-init) unconditionally converts the canonical HTTPS URL to its SSH form for git push origin:

PUSH_URL=$("$URL_BIN" --to ssh "$CANONICAL_HTTPS" 2>/dev/null || echo "$CANONICAL_HTTPS")

Users whose gh auth login defaulted to HTTPS (the gh default since 2.x) don't have an SSH key on the remote. The post-create git ls-remote $PUSH_URL step then hangs on an SSH prompt, exits, and the script bails with Remote not reachable via SSH:. Recovery required rerunning with --remote <https url>, which only works if the user knows the workaround.

Same hazard on the gitlab branch — glab config get git_protocol is parallel.

Fix

Three-step resolution for the push URL:

  1. --push-protocol https|ssh flag wins (lets the user pin regardless of CLI state — useful in CI / scripted setups).
  2. auto (default) queries the per-host CLI config:
    • github → gh config get git_protocol
    • gitlab → glab config get git_protocol
  3. Empty / unreadable / unknown value → SSH (historical default; no regression for users who never set git_protocol).

The ls-remote failure message also now points HTTPS users at the override flag, so the next attempt is one rerun away rather than a workaround hunt.

Tests

Extended the existing makeFakeGh / makeFakeGlab shims with an optional gitProtocol arg so they respond to gh config get git_protocol (and glab config get git_protocol). New describe('gstack-artifacts-init push protocol (issue #1348)') block, 7 cases:

  • gh git_protocol=https → origin URL is HTTPS.
  • gh git_protocol=ssh → origin URL is SSH (existing behavior preserved).
  • gh git_protocol unset → origin URL is SSH (legacy default preserved).
  • --push-protocol https overrides gh git_protocol=ssh.
  • --push-protocol ssh overrides gh git_protocol=https.
  • --push-protocol bogus exits 1 with Invalid --push-protocol.
  • gitlab branch: glab git_protocol=https → origin URL is HTTPS.
bun test test/gstack-artifacts-init.test.ts
# 23 pass, 0 fail (16 existing + 7 new)

Notes

  • No CHANGELOG / VERSION bump in the diff (maintainer-owned at squash-merge per repo convention).
  • --push-protocol deliberately covers only the local push URL; ~/.gstack-artifacts-remote.txt continues to store the canonical HTTPS form (codex Finding Add Claude Code marketplace configuration #10).
  • Does not touch gstack-artifacts-url --to ssh — that helper is still the right derivation primitive; only the auto policy in artifacts-init changes.

View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

@0xDevNinja

Copy link
Copy Markdown
Contributor Author

heads up, the red checks here aren't the diff. it's a fork PR so the runner has no secrets and the eval tests just die on an empty API key before anything actually runs. the rest is green.

if it's easier i can push this to a branch on the base repo and re-point the PR so it picks up secrets. lmk, no rush.

@time-attack

Copy link
Copy Markdown
Contributor

@16francej — recommend closing this PR because #2225 supersedes it with broader handling for providers and explicit remote schemes. This version still fails when the remote is explicitly configured for HTTPS. Please retain the provider-detection tests and attribution under #2225.

`gstack-artifacts-init` always converted the canonical HTTPS URL to its
SSH form for `git push origin`. Users on `gh config set git_protocol
https` (the `gh auth login` default) lack an SSH key on the remote, so
the post-create `git ls-remote $PUSH_URL` verification fails with a
cryptic SSH prompt and the script exits without finishing setup. Same
hazard on the gitlab branch.

Pre-fix the only recovery was rerunning with `--remote <https url>`,
which bypassed the canonicalization step entirely and required the user
to know the workaround.

Resolution order for the push URL:
  1. `--push-protocol https|ssh` flag wins.
  2. `auto` (default) reads `gh config get git_protocol` (github branch)
     or `glab config get git_protocol` (gitlab branch).
  3. Empty / unreadable config falls back to SSH — the historical
     default, kept so users who never set `git_protocol` see no change.

Error message after a failed `ls-remote` also points HTTPS users at the
override flag, so the next attempt is one rerun away.

Fixes garrytan#1348
…-push-protocol auto

The original git_protocol detection keyed only on --host, so it only ran
for remotes gstack creates via gh/glab. A URL the user hands us through
--remote, an existing origin, or a manual paste fell through to the SSH
default — silently rewriting an explicitly-configured HTTPS remote to
SSH. That's the July report on garrytan#1348: a user whose recovery URL was
HTTPS got it converted back to SSH and the push failed.

Track where REMOTE_URL came from. Under auto:
- explicit / existing / manual: keep the scheme the URL already states
  (git@|ssh:// -> ssh, http(s):// -> https, anything else preserved
  verbatim). Never consult git_protocol for a URL the user supplied.
- provider (gh/glab-created): honor git_protocol as before, SSH fallback.

Explicit --push-protocol https|ssh still overrides everything. The
reachability error now has a third branch for pass-through URLs.

Refs garrytan#1348.
@0xDevNinja
0xDevNinja force-pushed the fix/1348-honor-git-protocol branch from f12a6ee to c454e2a Compare July 16, 2026 08:44
@0xDevNinja

Copy link
Copy Markdown
Contributor Author

closed the gap you flagged rather than closing the PR. the explicit-HTTPS-remote case was real: the original detection only ran for gh/glab-created remotes, so a URL passed via --remote (or an existing/manual one) fell through to the SSH default and got rewritten. pushed a fix that tracks where the URL came from and preserves the scheme the user actually supplied, only consulting git_protocol for provider-created remotes. --push-protocol https|ssh still overrides.

added 4 regression tests, incl. one that pins an explicit HTTPS --remote staying HTTPS even with git_protocol=ssh reachable. verified they fail on the pre-fix bin. 27 pass.

happy to defer to #2225 if the maintainers prefer that direction, but this branch now covers the same case, keeps the provider-detection tests, and is rebased onto current main.

@capy-ai

capy-ai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for this fix! The bug it addresses (#1348) has since been fixed on main and the issue is closed, so I'm closing this PR as done. Re-verified against current main (v1.91.12.0). If you think part of your change is still missing, reply and we'll reopen. Really appreciate the contribution.

@capy-ai capy-ai Bot closed this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gstack-brain-init defaults to SSH remote, fails for HTTPS-configured gh

2 participants